﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace B121 {
    /// <summary>
    /// The item class
    /// </summary>
    public class ItemClass {
        /// <summary>
        /// Creates an item
        /// </summary>
        /// <param name="name">Name of the item</param>
        /// <param name="x">X-value of the item</param>
        /// <param name="y">Y-value of the item</param>
        /// <param name="z">Z-value of the item</param>
        public ItemClass(string name, int x, int y, int z, int weight) {
            Name = name;
            X = x;
            Y = y;
            Z = z;
            Weight = weight;
        }

        #region Properties
        /// <summary>
        /// Gets the name of the item
        /// </summary>
        public string Name {
            get { return _Name; }
            private set {
                if (value == null) { // Name cannot be null
                    throw new ArgumentNullException();
                } else if (value == "") { // Name cannot be empty
                    throw new ArgumentOutOfRangeException("An item cannot have an empty name");
                } else {
                    _Name = value;
                }
            }
        }
        private string _Name;

        /// <summary>
        /// Gets the weight of the item
        /// </summary>
        public int Weight {
            get { return _Weight; }
            private set {
                if (value < 1) { // Weight check
                    throw new ArgumentOutOfRangeException("An item cannot have a weight less than 1");
                } else {
                    _Weight = value;
                }
            }
        }
        private int _Weight;

        /// <summary>
        /// Gets the X-value of the item
        /// </summary>
        public int X {
            get { return _X; }
            set {
                if (value < 1) { // Size check
                    throw new ArgumentOutOfRangeException("An item cannot have a X-value less than 1");
                } else {
                    _X = value;
                }
            }
        }
        private int _X;

        /// <summary>
        /// Gets the Y-value of the item
        /// </summary>
        public int Y {
            get { return _Y; }
            set {
                if (value < 1) { // Size check
                    throw new ArgumentOutOfRangeException("An item cannot have a negative Y-value");
                } else {
                    _Y = value;
                }
            }
        }
        private int _Y;

        /// <summary>
        /// Gets the Z-value of the item
        /// </summary>
        public int Z {
            get { return _Z; }
            set {
                if (value < 1) { // Size check
                    throw new ArgumentOutOfRangeException("An item cannot have a Z-value less than 1");
                } else {
                    _Z = value;
                }
            }
        }
        private int _Z;

        /// <summary>
        /// Gets/sets offset X the item
        /// </summary>
        public int OffsetX { get; set; }

        /// <summary>
        /// Gets/sets offset Y of the item
        /// </summary>
        public int OffsetY { get; set; }

        /// <summary>
        /// Gets/sets offset Z of the item. Unused
        /// </summary>
        public int OffsetZ { get; set; }
        #endregion

        /// <summary>
        /// Returns the 2-dimensional rectangle the item
        /// </summary>
        /// <returns>A 2-dimensional rectangle, ready to draw</returns>
        public System.Drawing.Rectangle GetRectangle(int zoomLevel) {
            if (zoomLevel < 1) { zoomLevel = 1; } // Is zoomlevel okay? If not, make okay
            return new System.Drawing.Rectangle(OffsetX * zoomLevel, OffsetY * zoomLevel, X * zoomLevel, Y * zoomLevel);
        }
    }
}
